package com.kuangchi.oam.service.impl;

import com.kuangchi.oam.service.SystemService;
import com.kuangchi.oam.vo.SystemVO;
import com.sun.management.OperatingSystemMXBean;
import org.springframework.stereotype.Service;

import java.lang.management.ManagementFactory;

/**
 * @version v1.0
 * @类描述：
 * @项目名称：
 * @包名： com.kuangchi.oam.service.impl
 * @类名称：SystemServiceImpl
 * @创建人：YIHANG.XU
 * @创建时间：2021/6/2012:59 下午
 * @修改人：YIHANG.XU
 * @修改时间：2021/6/2012:59 下午
 * @修改备注：
 * @Copyright
 */
@Service
public class SystemServiceImpl implements SystemService {
    private static OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();

    @Override
    public SystemVO getSystemInfo() {

        return null;
    }

    public static int memoryLoad() {
        double totalvirtualMemory = osmxb.getTotalPhysicalMemorySize();
        double freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();

        double value = freePhysicalMemorySize / totalvirtualMemory;
        int percentMemoryLoad = (int) ((1 - value) * 100);
        return percentMemoryLoad;

    }
    public static int cpuLoad() {
        double cpuLoad = osmxb.getSystemCpuLoad();
        double processCpuLoad = osmxb.getProcessCpuLoad();

        int percentCpuLoad = (int) (cpuLoad * 100);
        return percentCpuLoad;

    }

    public static void main(String[] args) {
        int i = memoryLoad();
        int i1 = cpuLoad();
        System.out.println(i1);
        System.out.println(i);
    }
}
